package com.yundasys.lab15springbootes.lab15springbootes.controller;

import cn.easyes.core.conditions.LambdaEsQueryWrapper;
import com.yundasys.lab15springbootes.lab15springbootes.mapper.DocumentMapper;
import com.yundasys.lab15springbootes.lab15springbootes.model.Document;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @PACKAGE_NAME: com.yundasys.lab15springbootes.lab15springbootes.controller
 * @NAME: TestUseEeController
 * @USER: jiangta
 * @DATE: 2022/9/16
 * @TIME: 7:56 下午
 * @PROJECT_NAME: springboot-labs
 */
@RestController
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class TestUseEeController {
    private final DocumentMapper documentMapper;

    @GetMapping("/insert")
    public Integer insert() {
        // 初始化-> 新增数据
        Document document = new Document();
        document.setTitle("老汉");
        document.setContent("推*技术过硬");
        return documentMapper.insert(document);
    }

    @GetMapping("/search")
    public List<Document> search() {
        // 查询出所有标题为老汉的文档列表
        LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
        wrapper.eq(Document::getTitle, "老汉");
        return documentMapper.selectList(wrapper);
    }
}
